package com.kaishengit.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kaishengit.pojo.Goods;
import com.kaishengit.service.GoodsService;

@Controller
public class GoodsController {
	private GoodsService goodsService;
	
	@RequestMapping("/goodsList")
	public String findAll(Model model){
		List<Goods> goodsList = goodsService.findAll();
		model.addAttribute("goodsList", goodsList);
		return "goods_list";
	}
	@RequestMapping("addGoods")
	public String addGoods(Goods goods){
		goodsService.add(goods);
		return "redirect:/goodsList";
	}
	@RequestMapping("findById{id}")
	public @ResponseBody Goods findById(@PathVariable String id){
		Goods goods = goodsService.findById(id);
		return goods;
	}
	@RequestMapping("editGoods")
	public String edit(Goods goods){
		goodsService.edit(goods);
		return "redirect:/goodsList";
	}
	@RequestMapping("/delGoods{id}")
	public String del(@PathVariable String id){
		goodsService.del(id);
		return "redirect:/goodsList";
	}
	@Autowired
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	

}
